<template>
  <div>
    <el-date-picker
      v-model="queryParams.auditYearStartTime"
      format="yyyy"
      value-format="yyyy"
      type="year"
      placeholder="开始"
      clearable
      size="small"
      :picker-options="pickerStartAuditYear"
    ></el-date-picker>
    至
    <el-date-picker
      v-model="queryParams.auditYearEndTime"
      format="yyyy"
      value-format="yyyy"
      type="year"
      placeholder="结束"
      clearable
      size="small"
      :picker-options="pickerEndAuditYear"
    ></el-date-picker>
  </div>
</template>

<script>
    export default {
      name: "dataYearRange",
      props: {
          pData: Object
      },
      data() {
        return {
          queryParams: {
            auditYearStartTime: '',
            auditYearEndTime: '',
          },
          pickerStartAuditYear: {
            disabledDate: time => {
              if (this.queryParams.auditYearEndTime) {
                return time.getFullYear() > this.queryParams.auditYearEndTime
              }
            },
          },
          pickerEndAuditYear: {
            disabledDate: time => {
              if(this.queryParams.auditYearStartTime){
                return time.getFullYear() < this.queryParams.auditYearStartTime
              }
            }
          },
        };
      },
      watch: {
        // 'pData.zhi': {
        //   handler(newName, oldName) {
        //     let nameEn = this.pData.nameEn;
        //     let startTime = "";
        //     let endTime = "";
        //     if(newName){
        //       startTime = newName[0];
        //       endTime = newName[1];
        //     }
        //     let clickName = this.pData.onclickName;
        //     const data = {};
        //     data["start_"+nameEn] = startTime;
        //     data["end_"+nameEn] = endTime;
        //     this.$emit(clickName, data)
        //   },
        //   deep: true,
        // },
        'queryParams': {
          handler(newName, oldName) {
            let nameEn = this.pData.nameEn;
            console.log(newName)
            let startTime = nameEn.auditYearStartTime;
            let endTime = nameEn.auditYearEndTime;
            let clickName = this.pData.onclickName;
            const data = {};
            data["start_"+nameEn] = startTime;
            data["end_"+nameEn] = endTime;
            this.$emit(clickName, data)
          },
          deep: true,
        },
      },
      created() {},
      methods: {
        clearZhi() {
          this.pData.zhi = "";
          this.queryParams.auditYearStartTime = '';
          this.queryParams.auditYearEndTime = '';
        }
      },
    }
</script>

<style scoped>

</style>
